package arcane.object.game.map;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import arcane.jibx.io.Marshaller;

public class Tile {
	protected int[] layers;

	public Tile() {
		this(new int[] {});
	}

	public Tile(int[] tiles) {
		this.layers = tiles;
	}

	public void setLayers(int[] layers) {
		this.layers = layers;
	}
	
	public int[] getLayers(){
		return layers;
	}

	public boolean add(int tile) {
		expand();
		layers[layers.length - 1] = tile;
		return true;
	}

	public void render(Graphics2D g, BufferedImage[] img, int x, int y) {
		for (int i = 0; i < layers.length; i++) {
			g.drawImage(img[layers[i]], x, y, null);
		}
	}

	protected void expand() {
		int[] newAry = new int[layers.length + 1];
		for (int i = 0; i < layers.length; i++)
			newAry[i] = layers[i];
		layers = newAry;
	}
	
	public String toString(){
		return Marshaller.M1DIntAry(layers);
	}
}